﻿@model CatalogPagingFilteringModel.PriceRangeFilterModel
@using Nop.Web.Models.Catalog;
@{
    var selectedItem = Model.Items.FirstOrDefault(x => x.Selected);
}
@helper FormatPriceRangeText(CatalogPagingFilteringModel.PriceRangeFilterItem filterItem)
{
    string rangeText = "";
    if (String.IsNullOrWhiteSpace(filterItem.From))
    {
        rangeText = string.Format(T("Filtering.PriceRangeFilter.Under").Text, string.Format("<span class=\"PriceRange\">{0}</span>", filterItem.To));
    }
    else if (String.IsNullOrWhiteSpace(filterItem.To))
    {
        rangeText = string.Format(T("Filtering.PriceRangeFilter.Over").Text, string.Format("<span class=\"PriceRange\">{0}</span>", filterItem.From));
    }
    else
    {
        rangeText = string.Format("<span class=\"PriceRange\">{0}</span> - <span class=\"PriceRange\">{1}</span>", filterItem.From, filterItem.To);
    }
    <text>@Html.Raw(rangeText)</text>
}
@if (Model.Enabled)
{
    <h2>@T("Filtering.PriceRangeFilter")</h2>

    <div class="panel-group category-products" id="accordian-price">
        @if (selectedItem == null)
        {
            foreach (var item in Model.Items)
            {
                <div class="panel panel-default">
                        

                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a href="@item.FilterUrl">@FormatPriceRangeText(item)<i class="fa fa-angle-right pull-right"></i></a>
                        </h4>
                    </div>
                        
                

                        
                </div>
            }
        }else
            {
                <div class="panel panel-default">
                        

                    <div class="panel-heading">
                        <h4 class="panel-title">
                           <a href="@Model.RemoveFilterUrl" class="remove-price-range-filter">@FormatPriceRangeText(selectedItem)<br/>@T("Filtering.PriceRangeFilter.Remove")<i class="fa fa-times pull-right"></i></a>
                        </h4>
                    </div>
                        
                

                        
                </div>

                
            }
    </div>



    
}